const qcloud = require('../../vendor/qcloud-weapp-client-sdk/index.js')
const config = require('../../config.js')
const utils = require('../../utils.js')

//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    allCLassState: false,
    isBankAdmin: false,
    allUser:[],
    hasClock:[],
    noticeClockList:[],
    currentClass: {},
    classInfoDTOs: [],
    noticeDTOs: [],
    curindex: 0,
    cgId:0,
    content: "",
    time:'',
    timeCur:''
  },

  // tab切换
  switchClock(e) {
    this.setData({
      curindex: e.currentTarget.dataset.index
    })
  },

  //获取班级打卡
  obtainCardsForClass(id, date) {
    utils.ajaxFn({
      url: config.service.obtainCardsForClass,
      body: {
        date: date,
        ciId: id
      },
      callback: (data) => {
        let hasClockList = data.cardDTOs.map((value) => {
          value.user.Time = value.createTime.split(' ')[1]
          return value.user
        })

        

        this.setData({
          hasClock: hasClockList.map(v => v.uId)
        })

        
        this.setData({
          noticeDTOs: this.data.allUser.filter(v => this.data.hasClock.indexOf(v.uId) > -1)
        })

        this.setData({
          noticeClockList: this.data.allUser.filter(v => this.data.hasClock.indexOf(v.uId) === -1)
        })

      }
    })


  },
  
  // 获取成员列表
  obtainClassMembers() {
    utils.ajaxFn({
      url: config.service.obtainClassMembers,
      body: { 'ciId': app.globalData.presentClass.ciId },
      callback: (data) => {

        let notClockList = data.memberDTOs.map((value) => {
          value.user.Time = value.createTime.split(' ')[1]
          return value.user
        })

        this.setData({
          allUser: notClockList
        })
        

        this.obtainCardsForClass(app.globalData.presentClass.ciId, this.data.timeCur)

      }
    })
  },

  // 获取群组成员
  getobtainGroupMembers() {
    utils.ajaxFn({
      url: config.service.obtainGroupMembers,
      body: {
        cgId: this.data.cgId
      },
      callback: (data) => {
        let notClockList = data.memberDTOs.map((value) => {
          value.user.Time = value.createTime.split(' ')[1]
          return value.user
        })

        this.setData({
          allUser: notClockList
        })


        this.obtainCardsForClass(app.globalData.presentClass.ciId, this.data.timeCur)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      time: options.showTime
    })
    
    this.setData({
      timeCur: options.time
    })

    this.setData({
      cgId: options.cgId
    })

    this.data.cgId == 0 ? this.obtainClassMembers() : this.getobtainGroupMembers()

  }

})